# 给定一段英文文本
text = """
This is a sample text with several words. This text is a simple example to demonstrate the counting of each word. 
Each word in this text may appear multiple times, and the goal is to count the occurrences of each word.
"""

# 将文本转换为小写并分割成单词列表
words = text.lower().split()

# 创建一个字典来存储单词和对应的词频
word_count = {}

# 遍历单词列表并统计每个单词的次数
for word in words:
    # 去除单词中的标点符号
    word = word.strip(",.?!")
    if word in word_count:
        word_count[word] += 1
    else:
        word_count[word] = 1

# 按照词频从高到低排序
sorted_word_count = sorted(word_count.items(), key=lambda x: x[1], reverse=True)

# 打印输出结果
print("词频统计（从高到低）：")
for word, count in sorted_word_count:
    print(f"{word}: {count}")
